/*******************************************************************************
 * 
 * Designed by : A. Augustine Joseph Starting Date : 11-01-2003 Last modified by :
 * A. Augustine Joseph Last modified Date : 17-01-2003 Total number of Class : 1
 * Total number of Methods : 3 Class Description : The class is used for
 * changing the font and color of the table
 *  
 ******************************************************************************/


package com.jjprojects.earutility;
import java.awt.*;

import javax.swing.table.TableCellRenderer;
import javax.swing.*;
import javax.swing.border.LineBorder;

public class CustomTableRenderer extends JLabel implements TableCellRenderer
{
     Font font = new Font("Times New Roman", Font.PLAIN, 15);
     
     Color colrEqual = new Color(0,128,64);
     Color colrNotEqual = new Color(164,0,0);
     Color colrFileMissing = new Color(0,0,160);
     
     ImageIcon imgicnEqual = new ImageIcon("images/Equal.gif");
     ImageIcon imgicnNotEqual = new ImageIcon("images/NotEqual.gif");
     ImageIcon imgicnFileMissing = new ImageIcon("images/Star.gif");
     ImageIcon imgicnBlank = new ImageIcon();
//    Font fontBold = new Font("Times New Roman", Font.BOLD, 15);

//    Font fontMargin = new Font("Times New Roman", Font.BOLD, 25);

    int classid = 0;
    EARFilesComparingTool objEARFilesCompare = null;
    FilesComparingTool objFilesComparingTool = null;
    
    /******************************************************************************
    
    Method Description : Constructor used for diffencating the calling class and gettig some property from the calling class
    Method Parameter1 	: IndividualTeacherSchedule
    Method Parameter1 Value 	: Calling Class
    Method Parameter2 	: int
    Method Parameter2 Value 	: Calling Class ID
    
    Method Return Type : No
    Use of Return Value : No

  	******************************************************************************/
    public CustomTableRenderer(EARFilesComparingTool i,int ctrl)
  	{
        objEARFilesCompare = i;
    	classid=ctrl;
    	setOpaque(true);
    	setFont(font);
  	}
    
    public CustomTableRenderer(FilesComparingTool i,int ctrl)
    {
        objFilesComparingTool = i;
        classid=ctrl;
        setOpaque(true);
        setFont(font);
    }
    
    /***************************************************************************
     * 
     * Method Description : This method is used for displaying the cell value
     * correctly
     * 
     * Method Parameter1 : JTable Method Parameter1 Value : Curent Table Method
     * Parameter2 : Object Method Parameter2 Value : Current Value Method
     * Parameter3 : boolean Method Parameter3 Value : Checking weather the
     * current cell is selected Method Parameter4 : boolean Method Parameter4
     * Value : Checking weather the current cell is focus Method Parameter5 :
     * int Method Parameter5 Value : Current Row Method Parameter6 : int Method
     * Parameter6 Value : Current Column
     * 
     * Method Return Type : Component Use of Return Value : The Current Cell
     * Value
     *  
     **************************************************************************/
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column)
    {
        this.setFont(font);
        setBackground(Color.white);
        
        this.setHorizontalAlignment(JLabel.LEFT);
        if (classid == 1)
        {
            String strEqualityStatus = (String) objEARFilesCompare.vecEqualityStatus.get(row);
            
            if(strEqualityStatus.equals("EQUAL"))
            {
                if(column == 1)
                {
                    setIcon(imgicnEqual);
                    String strEqualityStatusDetails = (String) objEARFilesCompare.vecEqualityStatusDetails.get(row);
                    this.setToolTipText(strEqualityStatusDetails);
                    setValue(null);
                }
                else
                {
                    setForeground(colrEqual);
                    setIcon(imgicnBlank);
                    setValue(value);
                    this.setToolTipText(null);
                }
            }
            else if(strEqualityStatus.equals("NOT EQUAL"))
            {
                if(column == 1)
                {
                    setIcon(imgicnNotEqual);
                    String strEqualityStatusDetails = (String) objEARFilesCompare.vecEqualityStatusDetails.get(row);
                    this.setToolTipText(strEqualityStatusDetails);
                    setValue(null);
                }
                else
                {
                    setForeground(colrNotEqual);
                    setIcon(imgicnBlank);
                    setValue(value);
                    this.setToolTipText(null);
                }
            }
            else if(strEqualityStatus.equals("FILE MISSING"))
            {
                if(column == 1)
                {
                    setIcon(imgicnFileMissing);
                    String strEqualityStatusDetails = (String) objEARFilesCompare.vecEqualityStatusDetails.get(row);
                    this.setToolTipText(strEqualityStatusDetails);
                    setValue(null);
                }
                else
                {
                    setForeground(colrFileMissing);
                    setIcon(imgicnBlank);
                    setValue(value);
                    this.setToolTipText(null);
                }
            }
            if (isSelected)
            {
                setForeground(Color.BLACK);
            }
        }
        else if (classid == 2)
        {
            String strFirstFileName = (String) objFilesComparingTool.vecFirstFileContent.get(row);
            String strSecondFileName = (String) objFilesComparingTool.vecSecondFileContent.get(row);
            if(strFirstFileName.equals(strSecondFileName))
            {
                setForeground(Color.MAGENTA);                
            }
            else
            {
                setForeground(Color.GREEN);
            }            
            setValue(value);
        }
        return this;
    }

    /***************************************************************************
     * 
     * Method Description : This method is used for displaying the cell value
     * correctly
     * 
     * Method Parameter : Object Method Parameter Value : Current Value
     * 
     * Method Return Type : Void Use of Return Value : No
     *  
     **************************************************************************/
    protected void setValue(Object value)
    {
        setText((value == null) ? "" : value.toString());
    }
}